// 创建文件可读流
const fs = require('fs');
const path = require('path');

const filename = path.resolve(__dirname, 'cs.txt')
// 创建一个文件可读流
const rs = fs.createReadStream(filename, {
    encoding: 'utf-8',
    highWaterMark: 16
})

rs.on("open", function () {
    console.log('文件被打开了')
})

var buffer = Buffer.from('')
rs.on("data", function (chunk) {
    var buffer2 = Buffer.from(chunk)
    buffer = Buffer.concat([buffer, buffer2], buffer.byteLength + buffer2.byteLength)
    console.log('文件内容:', chunk)
})

rs.on("error", function () {
    console.log('文件读取出错')
})

rs.on("end", function () {
    //  buffer.toString('utf-8')
    console.log('文件读取完成！！')
})